package com.budwk.app.util.poiUtils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrFormatter;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.dto.DaYingLuStreetFireHiddenCheckWordDTO;
import com.budwk.app.sqfw.enums.DownLoadFileNameEnum;
import com.budwk.app.sqfw.vo.GenerateWordAndPdfUrlVO;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.PictureRenderData;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayOutputStream;
import java.util.*;

import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.*;

/**
 * @author ZY.Wang
 * @since 2023/9/26
 *
 * <p>
 * 大营路街道消防安全文档生成工具类
 * </p>
 */
public class DaYingLuStreetFireHiddenOfficeUtils {

    public static final String segSymbol = "#";
    public static final String otherSegSymbol = "其他:";

    /**
     * 生成大营路的安全排查pdf
     *
     * @param formSummary 数据DTO
     * @return pdf生成结果
     */
    public static GenerateWordAndPdfUrlVO createFireHiddenPDF(DaYingLuStreetFireHiddenCheckWordDTO formSummary) {

        // 一共可能生成4个pdf
        List<ByteArrayOutputStream> osList = Lists.newArrayList();

        Set<String> a5ConditionSet = Sets.newHashSet("大型商场、超市、酒店", "幼儿园、寄宿制学校、社会福利机构", "医院、诊所、卫生服务站", "劳动密集型企业、多业态混合经营场所", "其他重点消防安全场所");
        String a5 = formSummary.getA5();
        if (a5ConditionSet.contains(a5)) {
            // 生成云岩区消防安全风险隐患排查整治台账
            if (a5ConditionSet.contains(a5)) {
                createSafetyRiskStandingBook(formSummary, osList);
            }
        } else {
            // 云岩区小型经营性场所消防安全综合治理
            createSmallBusinessPremisesSafetyGoverRecord(formSummary, osList);

            // 餐饮经营服务场所消防安全巡查记录
            Set<String> a7Set = Sets.newHashSet(formSummary.getA7().split(","));
            if (a7Set.contains("瓶装液化气") || a7Set.contains("瓶装天然气") || a7Set.contains("瓶装二甲醚")) {
                createCateringPremisesSafetyVisRecord(formSummary, null, osList);
            }

            // 瓶装液化燃气用户安全检查登录表
            if (a7Set.contains("瓶装液化气") || a7Set.contains("瓶装天然气") || a7Set.contains("瓶装二甲醚")) {
                createBottleGasSafetyRegistration(formSummary, osList);
            }

            // 生成视频监督协管员日常检查记录
            String a28 = formSummary.getA28();
            if (StringUtils.isNotBlank(a28) && (a28.equals("餐饮") || a28.equals("副食"))) {
                createFoodSupInsRecord(formSummary, osList);
            }

            // 现场照片
            ByteArrayOutputStream sitePictureOS = createSitePicture(formSummary);
            osList.add(sitePictureOS);
        }
        //String fileName = StrFormatter.format("{}安全排查整治表{}", formSummary.getA1(), DateUtil.format(new Date(), "yyyyMMdd"));
        //zhangp 2023-12-13 文件名称格式统一
        String downloadFileName = DownLoadFileNameEnum.SAFETY_INVESTIGATE_RENOVATE.getName();
        String fileName = StrFormatter.format("{}{}{}", formSummary.getA1(),downloadFileName, DateUtil.format(new Date(), "yyyyMMdd"));

        return wordToPdfAndUpload(osList, fileName, formSummary.getUnitName() + "消防安全走访巡查表");
    }


    /**
     * 云岩区小型经营性场所消防安全综合治理
     *
     * @return 输出流
     */
//    private static ByteArrayOutputStream createSmallBusinessPremisesSafetyGoverRecord(DaYingLuStreetFireHiddenCheckWordDTO formSummary) {
//        Map<String, Object> smallBPParam = Maps.newHashMap();
//        smallBPParam.put("unitName", formSummary.getUnitName());
//        smallBPParam.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy年MM月dd日HH时"));
//        smallBPParam.put("a1", formSummary.getA1());
//        smallBPParam.put("a3", formSummary.getA3());
//        smallBPParam.put("a2", formSummary.getA2());
//        smallBPParam.put("a8", formSummary.getA8());
//        smallBPParam.put("a5", formSummary.getA5());
//        smallBPParam.put("a6", formSummary.getA6());
//
//        // 是否搭建夹层信息
//        boolean a29_1 = false, a29_2 = false, a29_3 = false, a29_4 = false;
//        String a29 = formSummary.getA29();
//        if (StringUtils.isNotBlank(a29)) {
//            if (a29.equals("否")) {
//                a29_4 = true;
//            } else {
//                a29_1 = true;
//                a29_2 = a29.contains("库房");
//                a29_3 = a29.contains("居住");
//            }
//        }
//        smallBPParam.put("a29_1", a29_1);
//        smallBPParam.put("a29_2", a29_2);
//        smallBPParam.put("a29_3", a29_3);
//        smallBPParam.put("a29_4", a29_4);
//        smallBPParam.put("a30", formSummary.getA30());
//
//        // 夹层楼板信息
//        String a31 = formSummary.getA31();
//        smallBPParam.put("a31", a31);
//
//        // 楼梯建筑材料
//        boolean a32_1 = false, a32_3 = false;
//        String a32_2 = "", a32_4 = "";
//
//        String a32 = formSummary.getA32();
//        if (StringUtils.isNotBlank(a32)) {
//            List<String> a32List = Lists.newArrayList(Splitter.on(segSymbol).split(a32));
//            if (a32.contains("可燃材料")) {
//                a32_1 = true;
//                if (a32List.size() > 0) a32_2 = a32List.get(1);
//            } else {
//                a32_3 = true;
//                if (a32List.size() > 0) a32_4 = a32List.get(1);
//            }
//        }
//        smallBPParam.put("a32_1", a32_1);
//        smallBPParam.put("a32_2", a32_2);
//        smallBPParam.put("a32_3", a32_3);
//        smallBPParam.put("a32_4", a32_4);
//
//        // 是否住人 当a33-a38有值为是的时候都是住人的
//        boolean reside_1 = false, reside_2 = true;
//
//        // 居住人数
//        smallBPParam.put("a34", formSummary.getA34());
//        // 层数
//        smallBPParam.put("a35", formSummary.getA35());
//
//        boolean a36_1 = false, a36_2 = false, a36_3 = false, a36_4 = false, a36_5 = false;
//        String a36 = formSummary.getA36();
//        if (StringUtils.isNotBlank(a36)) {
//            if (a36.equals("符合要求")) {
//                a36_1 = true;
//                a36_2 = true;
//                a36_3 = true;
//            }
//
//            if (a36.equals("设置卷帘门、铁栅栏等")) {
//                a36_1 = true;
//                a36_2 = true;
//                a36_4 = true;
//            }
//
//            if (a36.equals("无")) {
//                a36_5 = true;
//            }
//        }
//        smallBPParam.put("a36_1", a36_1);
//        smallBPParam.put("a36_2", a36_2);
//        smallBPParam.put("a36_3", a36_3);
//        smallBPParam.put("a36_4", a36_4);
//        smallBPParam.put("a36_5", a36_5);
//
//        String a37 = formSummary.getA37();
//        boolean a37_1 = false, a37_2 = false, a37_3 = false, a37_4 = false;
//        if (StringUtils.isNotBlank(a37)) {
//            if (a37.equals("符合要求")) {
//                a37_1 = true;
//                a37_2 = true;
//            }
//
//            if (a37.equals("设置防盗窗等")) {
//                a37_1 = true;
//                a37_3 = true;
//            }
//
//            if (a37.equals("无")) {
//                a37_4 = true;
//            }
//        }
//        smallBPParam.put("a37_1", a37_1);
//        smallBPParam.put("a37_2", a37_2);
//        smallBPParam.put("a37_3", a37_3);
//        smallBPParam.put("a37_4", a37_4);
//
//        // 住人形式
//        String a33 = formSummary.getA33();
//        if (StringUtils.isBlank(a33)) a33 = "";
//        String a33_2 = "";
//        if (a33.contains(otherSegSymbol)) {
//            a33_2 = a33.replaceFirst(otherSegSymbol, "");
//        }
//        smallBPParam.put("a33", a33);
//        smallBPParam.put("a33_2", a33_2);
//
//
//        // 经营与住区域是否有防火分隔
//        String a38 = formSummary.getA38();
//        if (StringUtils.isBlank(a38)) a38 = "";
//        boolean a38_1 = false, a38_3 = false;
//        String a38_2 = "", a38_4 = "";
//        List<String> a38List = Lists.newArrayList(Splitter.on(segSymbol).split(a38));
//        if (a38.contains("有")) {
//            a38_1 = true;
//            if (a38List.size() > 1) a38_2 = a38List.get(1);
//        } else if (a38.contains("无")) {
//            a38_3 = true;
//            if (a38List.size() > 1) a38_4 = a38List.get(1);
//        }
//        smallBPParam.put("a38_1", a38_1);
//        smallBPParam.put("a38_2", a38_2);
//        smallBPParam.put("a38_3", a38_3);
//        smallBPParam.put("a38_4", a38_4);
//
//        if (StringUtils.isNotBlank(formSummary.getA34())) {
//            reside_1 = true;
//            reside_2 = false;
//        }
//        if (StringUtils.isNotBlank(formSummary.getA35())) {
//            reside_1 = true;
//            reside_2 = false;
//        }
//        if (StringUtils.isNotBlank(a33) && !a33.equals("没有住人")) {
//            reside_1 = true;
//            reside_2 = false;
//        }
//        if (StringUtils.isNotBlank(a38)) {
//            reside_1 = true;
//            reside_2 = false;
//        }
//        smallBPParam.put("reside_1", reside_1);
//        smallBPParam.put("reside_2", reside_2);
//
//        // 火灾自动报警系统
//        String a41 = formSummary.getA41();
//        if (StringUtils.isBlank(a41)) a41 = "";
//        boolean a41_1 = false, a41_2 = false;
//        String a41_3 = "";
//        if (a41.equals("有")) {
//            a41_1 = true;
//        }
//        if (a41.equals("无")) {
//            a41_2 = true;
//        }
//        if (a41.startsWith(otherSegSymbol)) {
//            a41_3 = a41.replaceFirst(otherSegSymbol, "");
//        }
//        // wzy 2023-12-8 a41_1 a42_1 a43_1这几个字段为有的的时候需要按照下面这样处理
//        if (a41_2) a41_3 = "无需配备";
//
//        smallBPParam.put("a41_1", a41_1);
//        smallBPParam.put("a41_2", a41_2);
//        smallBPParam.put("a41_3", a41_3);
//
//        // 自动喷水灭水系统
//        String a42 = formSummary.getA42();
//        if (StringUtils.isBlank(a42)) a42 = "";
//        boolean a42_1 = false, a42_2 = false;
//        String a42_3 = "";
//        if (a42.equals("有")) {
//            a42_1 = true;
//        }
//        if (a42.equals("无")) {
//            a42_2 = true;
//        }
//
//        if (a42.startsWith(otherSegSymbol)) {
//            a42_3 = a41.replaceFirst(otherSegSymbol, "");
//        }
//        if (a42_2) a42_3 = "无需配备";
//        smallBPParam.put("a42_1", a42_1);
//        smallBPParam.put("a42_2", a42_2);
//        smallBPParam.put("a42_3", a42_3);
//
//        // 室内消火栓
//        String a43 = formSummary.getA43();
//        if (StringUtils.isBlank(a43)) a43 = "";
//        boolean a43_1 = false, a43_2 = false;
//        String a43_3 = "";
//        if (a43.equals("有")) {
//            a43_1 = true;
//        }
//        if (a43.equals("无")) {
//            a43_2 = true;
//        }
//        if (a43.startsWith(otherSegSymbol)) {
//            a43_3 = a43.replaceFirst(otherSegSymbol, "");
//        }
//        if (a43_2) a43_3 = "无需配备";
//        smallBPParam.put("a43_1", a43_1);
//        smallBPParam.put("a43_2", a43_2);
//        smallBPParam.put("a43_3", a43_3);
//
//        // 灭火器
//        boolean a44_1 = false, a44_3 = false;
//        String a44_2 = "";
//        String a44 = formSummary.getA44();
//        if (StringUtils.isNotBlank(a44) && !a44.equals("0")) {
//            a44_1 = true;
//            a44_2 = a44;
//        } else {
//            a44_3 = true;
//        }
//        smallBPParam.put("a44_1", a44_1);
//        smallBPParam.put("a44_2", a44_2);
//        smallBPParam.put("a44_3", a44_3);
//
//        // 消防设施情况其他
//        smallBPParam.put("a45", formSummary.getA45());
//
//        // 电器线路情况
//        String a46 = formSummary.getA46();
//        if (StringUtils.isBlank(a46)) a46 = "";
//        Set<String> a46Set = Sets.newHashSet(Splitter.on(segSymbol).split(a46));
//        List<String> a46List = Lists.newArrayList(Splitter.on(segSymbol).split(a46));
//        boolean a46_1 = false, a46_2 = false, a46_3 = false, a46_4 = false, a46_5 = false;
//        String a46_6 = "";
//        if (a46Set.contains("合格")) a46_1 = true;
//        else {
//            a46_2 = true;
//            if (a46Set.contains("乱拉乱接")) a46_3 = true;
//            if (a46Set.contains("使用假冒伪劣产品")) a46_4 = true;
//            if (a46Set.contains("超负荷用电")) a46_5 = true;
//        }
//        a46_6 = getSmallBusinessPremisesStr(a46List);
//        smallBPParam.put("a46_1", a46_1);
//        smallBPParam.put("a46_2", a46_2);
//        smallBPParam.put("a46_3", a46_3);
//        smallBPParam.put("a46_4", a46_4);
//        smallBPParam.put("a46_5", a46_5);
//        smallBPParam.put("a46_6", a46_6);
//
//        // 电动自行车使用情况
//        String a47 = formSummary.getA47();
//        if (StringUtils.isBlank(a47)) a47 = "";
//        Set<String> a47Set = Sets.newHashSet(Splitter.on(segSymbol).split(a47));
//        List<String> a47List = Lists.newArrayList(Splitter.on(segSymbol).split(a47));
//        boolean a47_1 = false, a47_2 = false, a47_3 = false, a47_4 = false, a47_5 = false;
//        String a47_6 = "";
//        if (a47Set.contains("无")) {
//            a47_5 = true;
//        } else {
//            a47_1 = true;
//            if (a47Set.contains("室内充电")) a47_2 = true;
//            if (a47Set.contains("室外充电")) a47_3 = true;
//            if (a47Set.contains("飞线充电")) a47_4 = true;
//        }
//        a47_6 = getSmallBusinessPremisesStr(a47List);
//        smallBPParam.put("a47_1", a47_1);
//        smallBPParam.put("a47_2", a47_2);
//        smallBPParam.put("a47_3", a47_3);
//        smallBPParam.put("a47_4", a47_4);
//        smallBPParam.put("a47_5", a47_5);
//        smallBPParam.put("a47_6", a47_6);
//
//        // 是否使用明火、高温加热、取暖设备
//        String a48 = formSummary.getA48();
//        if (StringUtils.isBlank(a48)) a48 = "";
//        boolean a48_1 = false, a48_2 = false, a48_4 = false;
//        String a48_3 = "", a48_5 = "";
//        List<String> a48List = Lists.newArrayList(Splitter.on(segSymbol).split(a48));
//        Set<String> a48Set = Sets.newHashSet(Splitter.on(segSymbol).split(a48));
//        if (a48Set.contains("否")) {
//            a48_4 = true;
//        } else {
//            a48_1 = true;
//            if (a48Set.contains("夹层")) a48_2 = true;
//        }
//        a48_3 = "";
//        a48_5 = getSmallBusinessPremisesStr(a48List);
//        smallBPParam.put("a48_1", a48_1);
//        smallBPParam.put("a48_2", a48_2);
//        smallBPParam.put("a48_3", a48_3);
//        smallBPParam.put("a48_4", a48_4);
//        smallBPParam.put("a48_5", a48_5);
//
//        // 是否存放易燃易爆危险品
//        String a49 = formSummary.getA49();
//        if (StringUtils.isBlank(a49)) a49 = "";
//        boolean a49_1 = false, a49_3 = false;
//        String a49_2 = "", a49_4 = "";
//        Set<String> a49Set = Sets.newHashSet(Splitter.on(segSymbol).split(a49));
//        List<String> a49List = Lists.newArrayList(Splitter.on(segSymbol).split(a49));
//        if (a49Set.contains("是")) {
//            a49_1 = true;
//            if (a49List.size() > 1) a49_2 = a49List.get(1);
//        } else {
//            a49_3 = true;
//        }
//        a49_4 = "";
//        smallBPParam.put("a49_1", a49_1);
//        smallBPParam.put("a49_2", a49_2);
//        smallBPParam.put("a49_3", a49_3);
//        smallBPParam.put("a49_4", a49_4);
//
//        // 宣传教育培训
//        smallBPParam.put("a21", formSummary.getA21());
//        smallBPParam.put("a22", formSummary.getA22());
//
//        smallBPParam.put("a20", formSummary.getA20());
//        smallBPParam.put("a12", formSummary.getA12());
//
//        // 检查人签名等
//        addWordUserSignature(smallBPParam, "a18NoSig", "a18Sigs", "a18Sig",
//                formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//        smallBPParam.put("a19", addWordPicture(formSummary.getA19(), 1.0F));
//
//        return generateWordDocument(smallBPParam, "daYingLu/smallBusinessPremisesSafetyGoverRecord.docx", "云岩区小型生产经营性场所安全治理记录", System.currentTimeMillis());
//    }

    /**
     * 云岩区小型经营性场所消防安全综合治理
     *
     * @return 输出流
     */
    private static void createSmallBusinessPremisesSafetyGoverRecord(DaYingLuStreetFireHiddenCheckWordDTO formSummary,
                                                                     List<ByteArrayOutputStream> byteArrayOutputStreams) {
        Map<String, Object> smallBPParam = Maps.newHashMap();
        smallBPParam.put("unitName", formSummary.getUnitName());
        smallBPParam.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy年MM月dd日HH时"));
        smallBPParam.put("a1", formSummary.getA1());
        smallBPParam.put("a3", formSummary.getA3());
        smallBPParam.put("a2", formSummary.getA2());
        smallBPParam.put("a8", formSummary.getA8());
        smallBPParam.put("a5", formSummary.getA5());
        smallBPParam.put("a6", formSummary.getA6());

        // 是否搭建夹层信息
        boolean a29_1 = false, a29_2 = false, a29_3 = false, a29_4 = false;
        String a29 = formSummary.getA29();
        if (StringUtils.isNotBlank(a29)) {
            if (a29.equals("否")) {
                a29_4 = true;
            } else {
                a29_1 = true;
                a29_2 = a29.contains("库房");
                a29_3 = a29.contains("居住");
            }
        }
        smallBPParam.put("a29_1", a29_1);
        smallBPParam.put("a29_2", a29_2);
        smallBPParam.put("a29_3", a29_3);
        smallBPParam.put("a29_4", a29_4);
        smallBPParam.put("a30", formSummary.getA30());

        // 夹层楼板信息
        String a31 = formSummary.getA31();
        smallBPParam.put("a31", a31);

        // 楼梯建筑材料
        boolean a32_1 = false, a32_3 = false;
        String a32_2 = "", a32_4 = "";

        String a32 = formSummary.getA32();
        if (StringUtils.isNotBlank(a32)) {
            List<String> a32List = Lists.newArrayList(Splitter.on(segSymbol).split(a32));
            if (a32.contains("可燃材料")) {
                a32_1 = true;
                if (a32List.size() > 0) a32_2 = a32List.get(1);
            } else {
                a32_3 = true;
                if (a32List.size() > 0) a32_4 = a32List.get(1);
            }
        }
        smallBPParam.put("a32_1", a32_1);
        smallBPParam.put("a32_2", a32_2);
        smallBPParam.put("a32_3", a32_3);
        smallBPParam.put("a32_4", a32_4);

        // 是否住人 当a33-a38有值为是的时候都是住人的
        boolean reside_1 = false, reside_2 = true;

        // 居住人数
        smallBPParam.put("a34", formSummary.getA34());
        // 层数
        smallBPParam.put("a35", formSummary.getA35());

        boolean a36_1 = false, a36_2 = false, a36_3 = false, a36_4 = false, a36_5 = false;
        String a36 = formSummary.getA36();
        if (StringUtils.isNotBlank(a36)) {
            if (a36.equals("符合要求")) {
                a36_1 = true;
                a36_2 = true;
                a36_3 = true;
            }

            if (a36.equals("设置卷帘门、铁栅栏等")) {
                a36_1 = true;
                a36_2 = true;
                a36_4 = true;
            }

            if (a36.equals("无")) {
                a36_5 = true;
            }
        }
        smallBPParam.put("a36_1", a36_1);
        smallBPParam.put("a36_2", a36_2);
        smallBPParam.put("a36_3", a36_3);
        smallBPParam.put("a36_4", a36_4);
        smallBPParam.put("a36_5", a36_5);

        String a37 = formSummary.getA37();
        boolean a37_1 = false, a37_2 = false, a37_3 = false, a37_4 = false;
        if (StringUtils.isNotBlank(a37)) {
            if (a37.equals("符合要求")) {
                a37_1 = true;
                a37_2 = true;
            }

            if (a37.equals("设置防盗窗等")) {
                a37_1 = true;
                a37_3 = true;
            }

            if (a37.equals("无")) {
                a37_4 = true;
            }
        }
        smallBPParam.put("a37_1", a37_1);
        smallBPParam.put("a37_2", a37_2);
        smallBPParam.put("a37_3", a37_3);
        smallBPParam.put("a37_4", a37_4);

        // 住人形式
        String a33 = formSummary.getA33();
        if (StringUtils.isBlank(a33)) a33 = "";
        String a33_2 = "";
        if (a33.contains(otherSegSymbol)) {
            a33_2 = a33.replaceFirst(otherSegSymbol, "");
        }
        smallBPParam.put("a33", a33);
        smallBPParam.put("a33_2", a33_2);


        // 经营与住区域是否有防火分隔
        String a38 = formSummary.getA38();
        if (StringUtils.isBlank(a38)) a38 = "";
        boolean a38_1 = false, a38_3 = false;
        String a38_2 = "", a38_4 = "";
        List<String> a38List = Lists.newArrayList(Splitter.on(segSymbol).split(a38));
        if (a38.contains("有")) {
            a38_1 = true;
            if (a38List.size() > 1) a38_2 = a38List.get(1);
        } else if (a38.contains("无")) {
            a38_3 = true;
            if (a38List.size() > 1) a38_4 = a38List.get(1);
        }
        smallBPParam.put("a38_1", a38_1);
        smallBPParam.put("a38_2", a38_2);
        smallBPParam.put("a38_3", a38_3);
        smallBPParam.put("a38_4", a38_4);

        if (StringUtils.isNotBlank(formSummary.getA34())) {
            reside_1 = true;
            reside_2 = false;
        }
        if (StringUtils.isNotBlank(formSummary.getA35())) {
            reside_1 = true;
            reside_2 = false;
        }
        if (StringUtils.isNotBlank(a33) && !a33.equals("没有住人")) {
            reside_1 = true;
            reside_2 = false;
        }
        if (StringUtils.isNotBlank(a38)) {
            reside_1 = true;
            reside_2 = false;
        }
        smallBPParam.put("reside_1", reside_1);
        smallBPParam.put("reside_2", reside_2);

        // 火灾自动报警系统
        String a41 = formSummary.getA41();
        if (StringUtils.isBlank(a41)) a41 = "";
        boolean a41_1 = false, a41_2 = false;
        String a41_3 = "";
        if (a41.equals("有")) {
            a41_1 = true;
        }
        if (a41.equals("无")) {
            a41_2 = true;
        }
        if (a41.startsWith(otherSegSymbol)) {
            a41_3 = a41.replaceFirst(otherSegSymbol, "");
        }
        // wzy 2023-12-8 a41_1 a42_1 a43_1这几个字段为有的的时候需要按照下面这样处理
        if (a41_2) a41_3 = "无需配备";

        smallBPParam.put("a41_1", a41_1);
        smallBPParam.put("a41_2", a41_2);
        smallBPParam.put("a41_3", a41_3);

        // 自动喷水灭水系统
        String a42 = formSummary.getA42();
        if (StringUtils.isBlank(a42)) a42 = "";
        boolean a42_1 = false, a42_2 = false;
        String a42_3 = "";
        if (a42.equals("有")) {
            a42_1 = true;
        }
        if (a42.equals("无")) {
            a42_2 = true;
        }

        if (a42.startsWith(otherSegSymbol)) {
            a42_3 = a41.replaceFirst(otherSegSymbol, "");
        }
        if (a42_2) a42_3 = "无需配备";
        smallBPParam.put("a42_1", a42_1);
        smallBPParam.put("a42_2", a42_2);
        smallBPParam.put("a42_3", a42_3);

        // 室内消火栓
        String a43 = formSummary.getA43();
        if (StringUtils.isBlank(a43)) a43 = "";
        boolean a43_1 = false, a43_2 = false;
        String a43_3 = "";
        if (a43.equals("有")) {
            a43_1 = true;
        }
        if (a43.equals("无")) {
            a43_2 = true;
        }
        if (a43.startsWith(otherSegSymbol)) {
            a43_3 = a43.replaceFirst(otherSegSymbol, "");
        }
        if (a43_2) a43_3 = "无需配备";
        smallBPParam.put("a43_1", a43_1);
        smallBPParam.put("a43_2", a43_2);
        smallBPParam.put("a43_3", a43_3);

        // 灭火器
        boolean a44_1 = false, a44_3 = false;
        String a44_2 = "";
        String a44 = formSummary.getA44();
        if (StringUtils.isNotBlank(a44) && !a44.equals("0")) {
            a44_1 = true;
            a44_2 = a44;
        } else {
            a44_3 = true;
        }
        smallBPParam.put("a44_1", a44_1);
        smallBPParam.put("a44_2", a44_2);
        smallBPParam.put("a44_3", a44_3);

        // 消防设施情况其他
        smallBPParam.put("a45", formSummary.getA45());

        // 电器线路情况
        String a46 = formSummary.getA46();
        if (StringUtils.isBlank(a46)) a46 = "";
        Set<String> a46Set = Sets.newHashSet(Splitter.on(segSymbol).split(a46));
        List<String> a46List = Lists.newArrayList(Splitter.on(segSymbol).split(a46));
        boolean a46_1 = false, a46_2 = false, a46_3 = false, a46_4 = false, a46_5 = false;
        String a46_6 = "";
        if (a46Set.contains("合格")) a46_1 = true;
        else {
            a46_2 = true;
            if (a46Set.contains("乱拉乱接")) a46_3 = true;
            if (a46Set.contains("使用假冒伪劣产品")) a46_4 = true;
            if (a46Set.contains("超负荷用电")) a46_5 = true;
        }
        a46_6 = getSmallBusinessPremisesStr(a46List);
        smallBPParam.put("a46_1", a46_1);
        smallBPParam.put("a46_2", a46_2);
        smallBPParam.put("a46_3", a46_3);
        smallBPParam.put("a46_4", a46_4);
        smallBPParam.put("a46_5", a46_5);
        smallBPParam.put("a46_6", a46_6);

        // 电动自行车使用情况
        String a47 = formSummary.getA47();
        if (StringUtils.isBlank(a47)) a47 = "";
        Set<String> a47Set = Sets.newHashSet(Splitter.on(segSymbol).split(a47));
        List<String> a47List = Lists.newArrayList(Splitter.on(segSymbol).split(a47));
        boolean a47_1 = false, a47_2 = false, a47_3 = false, a47_4 = false, a47_5 = false;
        String a47_6 = "";
        if (a47Set.contains("无")) {
            a47_5 = true;
        } else {
            a47_1 = true;
            if (a47Set.contains("室内充电")) a47_2 = true;
            if (a47Set.contains("室外充电")) a47_3 = true;
            if (a47Set.contains("飞线充电")) a47_4 = true;
        }
        a47_6 = getSmallBusinessPremisesStr(a47List);
        smallBPParam.put("a47_1", a47_1);
        smallBPParam.put("a47_2", a47_2);
        smallBPParam.put("a47_3", a47_3);
        smallBPParam.put("a47_4", a47_4);
        smallBPParam.put("a47_5", a47_5);
        smallBPParam.put("a47_6", a47_6);

        // 是否使用明火、高温加热、取暖设备
        String a48 = formSummary.getA48();
        if (StringUtils.isBlank(a48)) a48 = "";
        boolean a48_1 = false, a48_2 = false, a48_4 = false;
        String a48_3 = "", a48_5 = "";
        List<String> a48List = Lists.newArrayList(Splitter.on(segSymbol).split(a48));
        Set<String> a48Set = Sets.newHashSet(Splitter.on(segSymbol).split(a48));
        if (a48Set.contains("否")) {
            a48_4 = true;
        } else {
            a48_1 = true;
            if (a48Set.contains("夹层")) a48_2 = true;
        }
        a48_3 = "";
        a48_5 = getSmallBusinessPremisesStr(a48List);
        smallBPParam.put("a48_1", a48_1);
        smallBPParam.put("a48_2", a48_2);
        smallBPParam.put("a48_3", a48_3);
        smallBPParam.put("a48_4", a48_4);
        smallBPParam.put("a48_5", a48_5);

        // 是否存放易燃易爆危险品
        String a49 = formSummary.getA49();
        if (StringUtils.isBlank(a49)) a49 = "";
        boolean a49_1 = false, a49_3 = false;
        String a49_2 = "", a49_4 = "";
        Set<String> a49Set = Sets.newHashSet(Splitter.on(segSymbol).split(a49));
        List<String> a49List = Lists.newArrayList(Splitter.on(segSymbol).split(a49));
        if (a49Set.contains("是")) {
            a49_1 = true;
            if (a49List.size() > 1) a49_2 = a49List.get(1);
        } else {
            a49_3 = true;
        }
        a49_4 = "";
        smallBPParam.put("a49_1", a49_1);
        smallBPParam.put("a49_2", a49_2);
        smallBPParam.put("a49_3", a49_3);
        smallBPParam.put("a49_4", a49_4);

        // 宣传教育培训
        smallBPParam.put("a21", formSummary.getA21());
        smallBPParam.put("a22", formSummary.getA22());

        smallBPParam.put("a20", formSummary.getA20());
        smallBPParam.put("a12", formSummary.getA12());

        // 检查人签名等
        addWordUserSignature(smallBPParam, "a18NoSig", "a18Sigs", "a18Sig",
                formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
        smallBPParam.put("a19", addWordPicture(formSummary.getA19(), 1.0F));

        XWPFTemplate xwpfTemplate = generateWordDocument(smallBPParam, null,
                "daYingLu/smallBusinessPremisesSafetyGoverRecord.docx");
        NiceXWPFDocument xwpfDocument = xwpfTemplate.getXWPFDocument();
        try {
            xwpfDocument = PictureUtils.localImageSeal(xwpfDocument, "被检查场所名称", PictureUtils.getLocalImagePath(formSummary.getUnitName()),
                    40, -15, 115);
            ByteArrayOutputStream wordOutPutStream = new ByteArrayOutputStream();
            xwpfDocument.write(wordOutPutStream);
            byteArrayOutputStreams.add(wordOutPutStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            PictureUtils.close(xwpfTemplate, xwpfDocument);
        }
    }

    /**
     * 创建餐饮经营服务场所消防安全巡查记录
     *
     * @param formSummary 填表数据
     * @return 结果
     */
//    private static List<ByteArrayOutputStream> createCateringPremisesSafetyVisRecord(DaYingLuStreetFireHiddenCheckWordDTO formSummary
//            , DaYingLuStreetFireHiddenCheckWordDTO nextFormSummary) {
//
//        List<ByteArrayOutputStream> osList = Lists.newArrayList();
//
//        Map<String, Object> paramMap = Maps.newHashMap();
//        Date fillDate = formSummary.getFillDate();
//        int fillDateYear = DateUtil.year(fillDate);
//        int fillDateMonth = DateUtil.month(fillDate) + 1;
//        int fillDateDay = DateUtil.dayOfMonth(fillDate);
//        paramMap.put("fillDateYear", fillDateYear);
//        paramMap.put("fillDateMonth", fillDateMonth);
//        paramMap.put("fillDateDay", fillDateDay);
//        paramMap.put("a1", formSummary.getA1());
//        paramMap.put("a2", formSummary.getA2());
//        paramMap.put("a3", formSummary.getA3());
//        paramMap.put("a8", formSummary.getA8());
//
//        String a23 = formSummary.getA23();
//        List<String> a23List = Lists.newArrayList();
//        if (StringUtils.isBlank(a23)) {
//            for (int i = 0; i < 27; i++) a23List.add("否");  // 因为a23有可能不传值，所以对于没有传值的需要进行初始化
//        } else {
//            a23List = Lists.newArrayList(a23.split(","));
//        }
//        for (int a23Index = 0; a23Index < a23List.size(); a23Index++) {
//            String paramNamePrefix = "a23_";
//            String indexStr = a23List.get(a23Index);
//
//            boolean indexBool = indexStr.equals("是");
//
//            paramMap.put(paramNamePrefix + (a23Index + 1), indexBool);
//        }
//
//        String a60 = formSummary.getA60();
//        if (StringUtils.isBlank(a60)) a60 = JSONObject.toJSONString(Lists.newArrayList()); // 有可能前端没有传值 所以这个步骤就是进行初始化
//        List<String> a60List = JSONObject.parseArray(a60, String.class);
//        String a60_4Str = "";
//        if (a60List.size() > 5) {
//            List<String> a60_6List = JSONObject.parseArray(a60List.get(5), String.class);
//            a60_4Str = Joiner.on("、").join(a60_6List);
//        }
//        paramMap.put("a60_5", a60_4Str);
//
//        // 巡查结果
//        boolean visResult = false;
//
//        String a61 = formSummary.getA61();
//        if (StringUtils.isBlank(a61)) a61 = JSONObject.toJSONString(Lists.newArrayList());
//        if (StringUtils.isBlank(a61)) {
//            paramMap.put("a61_5", "");
//            paramMap.put("a25Month", "");
//            paramMap.put("a25Day", "");
//        } else {
//            String a61_5Str = "";
//            List<String> a61List = JSONObject.parseArray(a61, String.class);
//            if (a61List.size() > 5) {
//                Set<String> a61_5Set = Sets.newHashSet(JSONObject.parseArray(a61List.get(5), String.class));
//                a61_5Set.remove("");
//                if (a61_5Set.size() == 0) visResult = true;
//                a61_5Str = Joiner.on("、").join(a61_5Set);
//            }
//            paramMap.put("a61_5", a61_5Str);
//        }
//
//        // 复查情况
//        // 使用上一次a61的字段和这一次a61的字段进行对比
//        // 1、如果上一次的a61是空时（说明上一次的巡查时没有问题的） 不用生成复查表格
//        // 2、否则将此次的a61对比上一次的a61，如果上一次出现的这一次没有出现则是整改完成项
//        //    如果上一次出现的这一次还出现，将这些填充到复查情况的未整改项处
//
//        // 初始化复查数据
//        paramMap.put("fillDateMonthSec", "");
//        paramMap.put("fillDateDaySec", "");
//        paramMap.put("a61Rectify", "");
//        paramMap.put("a61NotRectify", "");
//
//        paramMap.put("a18NoSigSec", "");
//        paramMap.put("a18SigsSec", null);
//        paramMap.put("a19Sec", null);
//
//        if (formSummary.getLastCheckFormSummary() != null) {    // 此处用于递归判断
//            List<ByteArrayOutputStream> lastRecordOS = createCateringPremisesSafetyVisRecord(formSummary.getLastCheckFormSummary(), formSummary);
//            osList.addAll(lastRecordOS);
//        }
//
//        String curA61 = formSummary.getA61();
//        if (StringUtils.isNotBlank(curA61) && nextFormSummary != null) {
//            // 使用上一次的数据生成一次带复查情况的数据
//            List<String> rectifyList = JSONObject.parseArray(curA61, String.class);
//            Set<String> needRectifySet = Sets.newHashSet(JSONObject.parseArray(rectifyList.get(5), String.class));
//
//            List<String> nextRectifyList = Lists.newArrayList(JSONObject.parseArray(nextFormSummary.getA61(), String.class));
//            Set<String> nextNeedRectifySet = Sets.newHashSet(JSONObject.parseArray(nextRectifyList.get(5), String.class));
//
//            paramMap.put("fillDateMonthSec", fillDateMonth);
//            paramMap.put("fillDateDaySec", fillDateDay);
//
//            // 如果这一次全部都整改完成了
//            if (nextNeedRectifySet.size() == 0) {
//                paramMap.put("a61Rectify", Joiner.on("、").join(needRectifySet));
//                paramMap.put("a61NotRectify", "");
//                paramMap.put("a18NoSigSec", "");
//                paramMap.put("a18SigsSec", Lists.newArrayList());
//                paramMap.put("a19Sec", null);
//            } else {
//
//                // lastNeedRectifySet与needRectifySet的交集是未整改项
//                // lastNeedRectifySet有的，needRectifySet没有的 是已经整改项
//                Collection<String> notRectifyColl = CollUtil.intersection(nextNeedRectifySet, needRectifySet);
//
//                // 初始化已经整改的
//                Collection<String> rectifiedColl = Sets.newHashSet(needRectifySet);
//                rectifiedColl.removeAll(notRectifyColl);    // 去除未整改的就是已经整改的
//
//                paramMap.put("a61Rectify", Joiner.on("、").join(rectifiedColl));
//                paramMap.put("a61NotRectify", Joiner.on("、").join(notRectifyColl));
//
//                addWordUserSignature(paramMap, "a18NoSigSec", "a18SigsSec", "a18SigSec",
//                        formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//                paramMap.put("a19Sec", addWordPicture(formSummary.getA19(), 1.0F));
//
//                visResult = false;
//            }
//        }
//
//        paramMap.put("visResult", visResult);
//        if (visResult) {
//            paramMap.put("a25Month", "");
//            paramMap.put("a25Day", "");
//        } else {
//            String a25 = formSummary.getA25();
//            if (StringUtils.isNotBlank(a25)) {
//                DateTime a25DateTime = DateUtil.parse(a25, "yyyy-MM-dd");
//                paramMap.put("a25Month", a25DateTime.month() + 1);
//                paramMap.put("a25Day", a25DateTime.dayOfMonth());
//            } else {
//                // 因为a25有可能误传，所以这句话是为了避免出现问题
//                paramMap.put("a25Month", "");
//                paramMap.put("a25Day", "");
//            }
//        }
//
//        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig",
//                formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//        paramMap.put("a19", addWordPicture(formSummary.getA19(), 1.0F));
//
//        ByteArrayOutputStream currentOS = generateWordDocument(paramMap, "daYingLu/cateringPremisesSafetyVistRecord.docx", "云岩区餐饮经营服务场所消防安全巡查记录", System.currentTimeMillis());
//        osList.add(currentOS);
//
//        return osList;
//    }

    /**
     * 创建餐饮经营服务场所消防安全巡查记录
     *
     * @param formSummary 填表数据
     * @return 结果
     */
    private static void createCateringPremisesSafetyVisRecord(DaYingLuStreetFireHiddenCheckWordDTO formSummary
            , DaYingLuStreetFireHiddenCheckWordDTO nextFormSummary, List<ByteArrayOutputStream> byteArrayOutputStreams) {

        Map<String, Object> paramMap = Maps.newHashMap();
        Date fillDate = formSummary.getFillDate();
        int fillDateYear = DateUtil.year(fillDate);
        int fillDateMonth = DateUtil.month(fillDate) + 1;
        int fillDateDay = DateUtil.dayOfMonth(fillDate);
        paramMap.put("fillDateYear", fillDateYear);
        paramMap.put("fillDateMonth", fillDateMonth);
        paramMap.put("fillDateDay", fillDateDay);
        paramMap.put("a1", formSummary.getA1());
        paramMap.put("a2", formSummary.getA2());
        paramMap.put("a3", formSummary.getA3());
        paramMap.put("a8", formSummary.getA8());

        String a23 = formSummary.getA23();
        List<String> a23List = Lists.newArrayList();
        if (StringUtils.isBlank(a23)) {
            for (int i = 0; i < 27; i++) a23List.add("否");  // 因为a23有可能不传值，所以对于没有传值的需要进行初始化
        } else {
            a23List = Lists.newArrayList(a23.split(","));
        }
        for (int a23Index = 0; a23Index < a23List.size(); a23Index++) {
            String paramNamePrefix = "a23_";
            String indexStr = a23List.get(a23Index);

            boolean indexBool = indexStr.equals("是");

            paramMap.put(paramNamePrefix + (a23Index + 1), indexBool);
        }

        String a60 = formSummary.getA60();
        if (StringUtils.isBlank(a60)) a60 = JSONObject.toJSONString(Lists.newArrayList()); // 有可能前端没有传值 所以这个步骤就是进行初始化
        List<String> a60List = JSONObject.parseArray(a60, String.class);
        String a60_4Str = "";
        if (a60List.size() > 5) {
            List<String> a60_6List = JSONObject.parseArray(a60List.get(5), String.class);
            a60_4Str = Joiner.on("、").join(a60_6List);
        }
        paramMap.put("a60_5", a60_4Str);

        // 巡查结果
        boolean visResult = false;

        String a61 = formSummary.getA61();
        if (StringUtils.isBlank(a61)) a61 = JSONObject.toJSONString(Lists.newArrayList());
        if (StringUtils.isBlank(a61)) {
            paramMap.put("a61_5", "");
            paramMap.put("a25Month", "");
            paramMap.put("a25Day", "");
        } else {
            String a61_5Str = "";
            List<String> a61List = JSONObject.parseArray(a61, String.class);
            if (a61List.size() > 5) {
                Set<String> a61_5Set = Sets.newHashSet(JSONObject.parseArray(a61List.get(5), String.class));
                a61_5Set.remove("");
                if (a61_5Set.size() == 0) visResult = true;
                a61_5Str = Joiner.on("、").join(a61_5Set);
            }
            paramMap.put("a61_5", a61_5Str);
        }

        // 复查情况
        // 使用上一次a61的字段和这一次a61的字段进行对比
        // 1、如果上一次的a61是空时（说明上一次的巡查时没有问题的） 不用生成复查表格
        // 2、否则将此次的a61对比上一次的a61，如果上一次出现的这一次没有出现则是整改完成项
        //    如果上一次出现的这一次还出现，将这些填充到复查情况的未整改项处

        // 初始化复查数据
        paramMap.put("fillDateMonthSec", "");
        paramMap.put("fillDateDaySec", "");
        paramMap.put("a61Rectify", "");
        paramMap.put("a61NotRectify", "");

        paramMap.put("a18NoSigSec", "");
        paramMap.put("a18SigsSec", null);
        paramMap.put("a19Sec", null);

        if (formSummary.getLastCheckFormSummary() != null) {    // 此处用于递归判断
            createCateringPremisesSafetyVisRecord(formSummary.getLastCheckFormSummary(), formSummary, byteArrayOutputStreams);
        }

        String curA61 = formSummary.getA61();
        if (StringUtils.isNotBlank(curA61) && nextFormSummary != null) {
            // 使用上一次的数据生成一次带复查情况的数据
            List<String> rectifyList = JSONObject.parseArray(curA61, String.class);
            Set<String> needRectifySet = Sets.newHashSet(JSONObject.parseArray(rectifyList.get(5), String.class));

            List<String> nextRectifyList = Lists.newArrayList(JSONObject.parseArray(nextFormSummary.getA61(), String.class));
            Set<String> nextNeedRectifySet = Sets.newHashSet(JSONObject.parseArray(nextRectifyList.get(5), String.class));

            paramMap.put("fillDateMonthSec", fillDateMonth);
            paramMap.put("fillDateDaySec", fillDateDay);

            //----------------------start,（和何光沟通过，只要是复查，就要签名）
            // 如果这一次全部都整改完成了
//            if (nextNeedRectifySet.size() == 0) {
//                paramMap.put("a61Rectify", Joiner.on("、").join(needRectifySet));
//                paramMap.put("a61NotRectify", "");
//                paramMap.put("a18NoSigSec", "");
//                paramMap.put("a18SigsSec", Lists.newArrayList());
//                paramMap.put("a19Sec", null);
//            } else {
//
//                // lastNeedRectifySet与needRectifySet的交集是未整改项
//                // lastNeedRectifySet有的，needRectifySet没有的 是已经整改项
//                Collection<String> notRectifyColl = CollUtil.intersection(nextNeedRectifySet, needRectifySet);
//
//                // 初始化已经整改的
//                Collection<String> rectifiedColl = Sets.newHashSet(needRectifySet);
//                rectifiedColl.removeAll(notRectifyColl);    // 去除未整改的就是已经整改的
//
//                paramMap.put("a61Rectify", Joiner.on("、").join(rectifiedColl));
//                paramMap.put("a61NotRectify", Joiner.on("、").join(notRectifyColl));
//
//                addWordUserSignature(paramMap, "a18NoSigSec", "a18SigsSec", "a18SigSec",
//                        formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//                paramMap.put("a19Sec", addWordPicture(formSummary.getA19(), 1.0F));
//
//                visResult = false;
//            }
            //-----------------------------end

            // lastNeedRectifySet与needRectifySet的交集是未整改项
            // lastNeedRectifySet有的，needRectifySet没有的 是已经整改项
            Collection<String> notRectifyColl = CollUtil.intersection(nextNeedRectifySet, needRectifySet);

            // 初始化已经整改的
            Collection<String> rectifiedColl = Sets.newHashSet(needRectifySet);
            rectifiedColl.removeAll(notRectifyColl);    // 去除未整改的就是已经整改的

            paramMap.put("a61Rectify", Joiner.on("、").join(rectifiedColl));
            paramMap.put("a61NotRectify", Joiner.on("、").join(notRectifyColl));

            addWordUserSignature(paramMap, "a18NoSigSec", "a18SigsSec", "a18SigSec",
                    formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
            paramMap.put("a19Sec", addWordPicture(formSummary.getA19(), 1.0F));

            visResult = false;
        }

        paramMap.put("visResult", visResult);
        if (visResult) {
            paramMap.put("a25Month", "");
            paramMap.put("a25Day", "");
        } else {
            String a25 = formSummary.getA25();
            if (StringUtils.isNotBlank(a25)) {
                DateTime a25DateTime = DateUtil.parse(a25, "yyyy-MM-dd");
                paramMap.put("a25Month", a25DateTime.month() + 1);
                paramMap.put("a25Day", a25DateTime.dayOfMonth());
            } else {
                // 因为a25有可能误传，所以这句话是为了避免出现问题
                paramMap.put("a25Month", "");
                paramMap.put("a25Day", "");
            }
        }

        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig",
                formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
        paramMap.put("a19", addWordPicture(formSummary.getA19(), 1.0F));

        XWPFTemplate xwpfTemplate = generateWordDocument(paramMap, null,
                "daYingLu/cateringPremisesSafetyVistRecord.docx");
        NiceXWPFDocument xwpfDocument = xwpfTemplate.getXWPFDocument();
        try {
            xwpfDocument = PictureUtils.localImageSeal(xwpfDocument, "巡查人员签名", PictureUtils.getLocalImagePath(formSummary.getUnitName()),
                    50, -53, 115);
            ByteArrayOutputStream wordOutPutStream = new ByteArrayOutputStream();
            xwpfDocument.write(wordOutPutStream);
            byteArrayOutputStreams.add(wordOutPutStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            PictureUtils.close(xwpfTemplate, xwpfDocument);
        }
    }

    /**
     * 创建瓶装液化燃气用户安全检查登录表
     *
     * @param formSummary 填表数据
     * @return 结果
     */
//    private static ByteArrayOutputStream createBottleGasSafetyRegistration(DaYingLuStreetFireHiddenCheckWordDTO formSummary) {
//        Map<String, Object> paramMap = Maps.newHashMap();
//        paramMap.put("area", formSummary.getArea());
//        paramMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));
//        paramMap.put("a1", formSummary.getA1());
//        paramMap.put("a2", formSummary.getA2());
//        paramMap.put("a11", formSummary.getA11());
//        paramMap.put("a8", formSummary.getA8());
//        paramMap.put("a53", formSummary.getA53());
//        paramMap.put("a14", formSummary.getA14());
//        paramMap.put("a3", formSummary.getA3());
//
//        String a23 = formSummary.getA23();
//        List<String> a23List = Lists.newArrayList();
//        if (StringUtils.isBlank(a23)) {
//            for (int i = 0; i < 27; i++) a23List.add("否");  // 因为a23有可能不传值，所以对于没有传值的需要进行初始化
//        } else a23List = Lists.newArrayList(a23.split(","));
//        for (int a23Index = 0; a23Index < a23List.size(); a23Index++) {
//            String keywordPrefix = "a23_";
//            String keyword = (a23Index + 1) + "";
//            String value = a23List.get(a23Index);
//
//            keyword = keywordPrefix + keyword;
//            boolean valueBool = value.equals("是");
//            paramMap.put(keyword, valueBool);
//        }
//
//        paramMap.put("a20", formSummary.getA20());
//        paramMap.put("a25", formSummary.getA25());
//
//        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig",
//                formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//        paramMap.put("a19", addWordPicture(formSummary.getA19(), 1.0F));
//
//        return generateWordDocument(paramMap, "daYingLu/bottleGasSafetyRegistration.docx", "瓶装野花燃气用户安全检查登记表", System.currentTimeMillis());
//    }

    /**
     * 创建瓶装液化燃气用户安全检查登录表
     *
     * @param formSummary 填表数据
     * @return 结果
     */
    private static void createBottleGasSafetyRegistration(DaYingLuStreetFireHiddenCheckWordDTO formSummary,
                                                          List<ByteArrayOutputStream> byteArrayOutputStreams) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("area", formSummary.getArea());
        paramMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));
        paramMap.put("a1", formSummary.getA1());
        paramMap.put("a2", formSummary.getA2());
        paramMap.put("a11", formSummary.getA11());
        paramMap.put("a8", formSummary.getA8());
        paramMap.put("a53", formSummary.getA53());
        paramMap.put("a14", formSummary.getA14());
        paramMap.put("a3", formSummary.getA3());

        String a23 = formSummary.getA23();
        List<String> a23List = Lists.newArrayList();
        if (StringUtils.isBlank(a23)) {
            for (int i = 0; i < 27; i++) a23List.add("否");  // 因为a23有可能不传值，所以对于没有传值的需要进行初始化
        } else a23List = Lists.newArrayList(a23.split(","));
        for (int a23Index = 0; a23Index < a23List.size(); a23Index++) {
            String keywordPrefix = "a23_";
            String keyword = (a23Index + 1) + "";
            String value = a23List.get(a23Index);

            keyword = keywordPrefix + keyword;
            boolean valueBool = value.equals("是");
            paramMap.put(keyword, valueBool);
        }

        paramMap.put("a20", formSummary.getA20());
        paramMap.put("a25", formSummary.getA25());

        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig",
                formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
        paramMap.put("a19", addWordPicture(formSummary.getA19(), 1.0F));

        XWPFTemplate xwpfTemplate = generateWordDocument(paramMap, null,
                "daYingLu/bottleGasSafetyRegistration.docx");
        NiceXWPFDocument xwpfDocument = xwpfTemplate.getXWPFDocument();
        try {
            xwpfDocument = PictureUtils.localImageSeal(xwpfDocument, "排查人员", PictureUtils.getLocalImagePath(formSummary.getUnitName()),
                    20, -53, 115);
            ByteArrayOutputStream wordOutPutStream = new ByteArrayOutputStream();
            xwpfDocument.write(wordOutPutStream);
            byteArrayOutputStreams.add(wordOutPutStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            PictureUtils.close(xwpfTemplate, xwpfDocument);
        }
    }

//    private static ByteArrayOutputStream createFoodSupInsRecord(DaYingLuStreetFireHiddenCheckWordDTO formSummary) {
//        Map<String, Object> paramMap = Maps.newHashMap();
//        paramMap.put("a1", formSummary.getA1());
//        paramMap.put("a2", formSummary.getA2());
//        paramMap.put("a3", formSummary.getA3());
//        paramMap.put("a8", formSummary.getA8());
//        paramMap.put("a28", formSummary.getA28());
//        paramMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));
//
//        String a62 = formSummary.getA62();
//        if (StringUtils.isBlank(a62)) {
//            List<List<List<String>>> a62List = Lists.newArrayList();
//            for (int i = 0; i < 4; i++) {
//                List<List<String>> a62ItemList = Lists.newArrayList();
//                for (int j = 0; j < 32; j++) {
//                    List<String> secList = Lists.newArrayList();
//                    a62ItemList.add(secList);
//                }
//                a62List.add(a62ItemList);
//            }
//            a62 = JSONObject.toJSONString(a62List);
//        }
//        List<String> a62List = Lists.newArrayList(Splitter.on(",").split(a62));
//        for (int a64Index = 0; a64Index < a62List.size(); a64Index++) {
//            String key = "a62_" + (a64Index + 1);
//            String value = a62List.get(a64Index);
//            boolean boolValue = true;
//            if (StringUtils.isNotBlank(value)) boolValue = value.equals("是");
//
//            paramMap.put(key, boolValue);
//        }
//
//        PictureRenderData a19Pic = addWordPicture(formSummary.getA19(), 1.0F);
//        paramMap.put("a19", a19Pic);
//
//        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig", formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//
//        return generateWordDocument(paramMap, "daYingLu/foodSupInsRecord.docx", "云岩区视频监督协管员日常检查记录表", System.currentTimeMillis());
//    }

    /**
     * 云岩区视频监督协管员日常检查记录表
     * @param formSummary
     * @return
     */
    private static void createFoodSupInsRecord(DaYingLuStreetFireHiddenCheckWordDTO formSummary,
                                               List<ByteArrayOutputStream> byteArrayOutputStreams) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("a1", formSummary.getA1());
        paramMap.put("a2", formSummary.getA2());
        paramMap.put("a3", formSummary.getA3());
        paramMap.put("a8", formSummary.getA8());
        paramMap.put("a28", formSummary.getA28());
        paramMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));

        String a62 = formSummary.getA62();
        if (StringUtils.isBlank(a62)) {
            List<List<List<String>>> a62List = Lists.newArrayList();
            for (int i = 0; i < 4; i++) {
                List<List<String>> a62ItemList = Lists.newArrayList();
                for (int j = 0; j < 32; j++) {
                    List<String> secList = Lists.newArrayList();
                    a62ItemList.add(secList);
                }
                a62List.add(a62ItemList);
            }
            a62 = JSONObject.toJSONString(a62List);
        }
        List<String> a62List = Lists.newArrayList(Splitter.on(",").split(a62));
        for (int a64Index = 0; a64Index < a62List.size(); a64Index++) {
            String key = "a62_" + (a64Index + 1);
            String value = a62List.get(a64Index);
            boolean boolValue = true;
            if (StringUtils.isNotBlank(value)) boolValue = value.equals("是");

            paramMap.put(key, boolValue);
        }

        PictureRenderData a19Pic = addWordPicture(formSummary.getA19(), 1.0F);
        paramMap.put("a19", a19Pic);

        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig", formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);

        XWPFTemplate xwpfTemplate = generateWordDocument(paramMap, null,
                "daYingLu/foodSupInsRecord.docx");
        NiceXWPFDocument xwpfDocument = xwpfTemplate.getXWPFDocument();
        try {
            xwpfDocument = PictureUtils.localImageSeal(xwpfDocument, "协管员签字", PictureUtils.getLocalImagePath(formSummary.getUnitName()),
                    65, -53, 115);
            ByteArrayOutputStream wordOutPutStream = new ByteArrayOutputStream();
            xwpfDocument.write(wordOutPutStream);
            byteArrayOutputStreams.add(wordOutPutStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            PictureUtils.close(xwpfTemplate, xwpfDocument);
        }
    }

//    private static ByteArrayOutputStream createSafetyRiskStandingBook(DaYingLuStreetFireHiddenCheckWordDTO formSummary) {
//        Map<String, Object> paramMap = Maps.newHashMap();
//
//        paramMap.put("a63", formSummary.getA63());
//        paramMap.put("a1", formSummary.getA1());
//        paramMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));
//        paramMap.put("a3", formSummary.getA3());
//        paramMap.put("a2", formSummary.getA2());
//        paramMap.put("a8", formSummary.getA8());
//
//        String a64 = formSummary.getA64();
//        if (StringUtils.isBlank(a64)) a64 = JSONObject.toJSONString(Lists.newArrayList());
//        List<String> a64List = JSONObject.parseArray(a64, String.class);
//        String a64_1Str = a64List.get(0);
//        List<String> a64_1List = JSONObject.parseArray(a64_1Str, String.class);
//        for (int index = 0; index < a64_1List.size(); index++) {
//            String key = "a64_" + (index + 1);
//            String value = a64_1List.get(index);
//
//            boolean boolValue = !value.equals("否");
//            paramMap.put(key, boolValue);
//        }
//        paramMap.put("a20", formSummary.getA20());
//        paramMap.put("a12", formSummary.getA12());
//
//        String a25Str = "无";
//        String a25 = formSummary.getA25();
//        if (StringUtils.isNotBlank(a25)) {
//            DateTime a25Date = DateUtil.parse(a25, "yyyy-MM-dd");
//            long betweenDay = DateUtil.betweenDay(formSummary.getFillDate(), a25Date, true);
//            if (betweenDay == 0) a25Str = "当天";
//            else a25Str = betweenDay + "天";
//        }
//        paramMap.put("a25Str", a25Str);
//        paramMap.put("a65", formSummary.getA65());
//
//        PictureRenderData a19Pic = addWordPicture(formSummary.getA19(), 1.0F);
//        paramMap.put("a19", a19Pic);
//
//        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig", formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);
//
//        return generateWordDocument(paramMap, "daYingLu/safetyRiskRecStandingBook.docx", "云岩区视频监督协管员日常检查记录表", System.currentTimeMillis());
//
//    }

    /**
     * 云岩区视频监督协管员日常检查记录表
     * @param formSummary
     * @return
     */
    private static void createSafetyRiskStandingBook(DaYingLuStreetFireHiddenCheckWordDTO formSummary,
                                                     List<ByteArrayOutputStream> byteArrayOutputStreams) {
        Map<String, Object> paramMap = Maps.newHashMap();

        paramMap.put("a63", formSummary.getA63());
        paramMap.put("a1", formSummary.getA1());
        paramMap.put("fillDateStr", DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));
        paramMap.put("a3", formSummary.getA3());
        paramMap.put("a2", formSummary.getA2());
        paramMap.put("a8", formSummary.getA8());

        String a64 = formSummary.getA64();
        if (StringUtils.isBlank(a64)) a64 = JSONObject.toJSONString(Lists.newArrayList());
        List<String> a64List = JSONObject.parseArray(a64, String.class);
        String a64_1Str = a64List.get(0);
        List<String> a64_1List = JSONObject.parseArray(a64_1Str, String.class);
        for (int index = 0; index < a64_1List.size(); index++) {
            String key = "a64_" + (index + 1);
            String value = a64_1List.get(index);

            boolean boolValue = !value.equals("否");
            paramMap.put(key, boolValue);
        }
        paramMap.put("a20", formSummary.getA20());
        paramMap.put("a12", formSummary.getA12());

        String a25Str = "无";
        String a25 = formSummary.getA25();
        if (StringUtils.isNotBlank(a25)) {
            DateTime a25Date = DateUtil.parse(a25, "yyyy-MM-dd");
            long betweenDay = DateUtil.betweenDay(formSummary.getFillDate(), a25Date, true);
            if (betweenDay == 0) a25Str = "当天";
            else a25Str = betweenDay + "天";
        }
        paramMap.put("a25Str", a25Str);
        paramMap.put("a65", formSummary.getA65());

        PictureRenderData a19Pic = addWordPicture(formSummary.getA19(), 1.0F);
        paramMap.put("a19", a19Pic);

        addWordUserSignature(paramMap, "a18NoSig", "a18Sigs", "a18Sig", formSummary.getA18NoSignatureUsers(), formSummary.getA18UserSignatureUrls(), 1.0F);

        XWPFTemplate xwpfTemplate = generateWordDocument(paramMap, null,
                "daYingLu/safetyRiskRecStandingBook.docx");
        NiceXWPFDocument xwpfDocument = xwpfTemplate.getXWPFDocument();
        try {
            xwpfDocument = PictureUtils.localImageSeal(xwpfDocument, "协管员签字", PictureUtils.getLocalImagePath(formSummary.getUnitName()),
                    65, -53, 115);
            ByteArrayOutputStream wordOutPutStream = new ByteArrayOutputStream();
            xwpfDocument.write(wordOutPutStream);
            byteArrayOutputStreams.add(wordOutPutStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            PictureUtils.close(xwpfTemplate, xwpfDocument);
        }
    }

    /**
     * 创建现场照片pdf
     *
     * @param formSummary 现场照片填表数据
     * @return 结果
     */
    private static ByteArrayOutputStream createSitePicture(DaYingLuStreetFireHiddenCheckWordDTO formSummary) {
        List<SitePictureOfficeUtils.SitePictureContent> sitePictureContentList = Lists.newArrayList();
        if (StringUtils.isNotBlank(formSummary.getA67())) {
            List<String> pictureList = Lists.newArrayList(Lists.newArrayList(formSummary.getA67().split(",")));
            String textStr = "附件：{} {} 走访照片";
            textStr = StrFormatter.format(textStr, formSummary.getA1(), DateUtil.format(formSummary.getCreateDate(), "yyyy-MM-dd"));
            sitePictureContentList.add(new SitePictureOfficeUtils.SitePictureContent(textStr, pictureList));
        }
        if (StringUtils.isNotBlank(formSummary.getA9())) {
            List<String> pictureList = Lists.newArrayList(Lists.newArrayList(formSummary.getA9().split(",")));
            String textStr = "附件：{} {} 场所隐患照片";
            textStr = StrFormatter.format(textStr, formSummary.getA1(), DateUtil.format(formSummary.getCreateDate(), "yyyy-MM-dd"));
            sitePictureContentList.add(new SitePictureOfficeUtils.SitePictureContent(textStr, pictureList));
        }
        if (StringUtils.isNotBlank(formSummary.getA10())) {
            List<String> pictureList = Lists.newArrayList(Lists.newArrayList(formSummary.getA10().split(",")));
            String textStr = "附件：{} {} 隐患整改后照片";
            textStr = StrFormatter.format(textStr, formSummary.getA1(), DateUtil.format(formSummary.getCreateDate(), "yyyy-MM-dd"));
            sitePictureContentList.add(new SitePictureOfficeUtils.SitePictureContent(textStr, pictureList));
        }
        if (StringUtils.isNotBlank(formSummary.getA39())) {
            List<String> pictureList = Lists.newArrayList(Lists.newArrayList(formSummary.getA39().split(",")));
            String textStr = "附件：{} {} 违规住人照片";
            textStr = StrFormatter.format(textStr, formSummary.getA1(), DateUtil.format(formSummary.getFillDate(), "yyyy-MM-dd"));
            sitePictureContentList.add(new SitePictureOfficeUtils.SitePictureContent(textStr, pictureList));
        }
        if (StringUtils.isNotBlank(formSummary.getA40())) {
            List<String> pictureList = Lists.newArrayList(Lists.newArrayList(formSummary.getA40().split(",")));
            String textStr = "附件：{} {} 住人整改后照片";
            textStr = StrFormatter.format(textStr, formSummary.getA1(), DateUtil.format(formSummary.getCreateDate(), "yyyy-MM-dd"));
            sitePictureContentList.add(new SitePictureOfficeUtils.SitePictureContent(textStr, pictureList));
        }
        return SitePictureOfficeUtils.createSitePicture(sitePictureContentList);
    }

    /**
     * 从数据中获取字符串
     *
     * @param list 字符串数组
     * @return 结果
     */
    private static String getSmallBusinessPremisesStr(List<String> list) {
        return getSmallBusinessPremisesStr(list, null);
    }

    /**
     * 从数据中获取字符串
     *
     * @param list 字符串数组
     * @return 结果
     */
    private static String getSmallBusinessPremisesStr(List<String> list, String keyword) {
        if (StringUtils.isBlank(keyword)) keyword = otherSegSymbol;

        String resultStr = "";
        for (String s : list) {
            if (s.contains(keyword)) {
                resultStr = s.replace(keyword, "");
                break;
            }
        }
        return resultStr;
    }
}
